package us.mooresr.geartrack.server.handler;

import us.mooresr.geartrack.server.DAO;
import us.mooresr.geartrack.shared.action.PutLocationResult;
import us.mooresr.geartrack.shared.action.PutLocationAction;
import us.mooresr.geartrack.shared.model.Location;

import com.gwtplatform.dispatch.server.ExecutionContext;
import com.gwtplatform.dispatch.server.actionhandler.ActionHandler;
import com.gwtplatform.dispatch.shared.ActionException;

public class PutLocationActionHandler implements ActionHandler<PutLocationAction, PutLocationResult> {

	@Override
	public PutLocationResult execute(PutLocationAction action,
			ExecutionContext arg1) throws ActionException {
		DAO dao = new DAO();
		
		Location newLocation = action.getLocationIn();
		
		dao.ofy().put(newLocation);
		
		PutLocationResult result = new PutLocationResult(newLocation);
		
		return result;
	}

	@Override
	public Class<PutLocationAction> getActionType() {
		return PutLocationAction.class;
	}

	@Override
	public void undo(PutLocationAction arg0, PutLocationResult arg1,
			ExecutionContext arg2) throws ActionException {
		// TODO Auto-generated method stub
		
	}

}
